package com.snailhd.framework.i18n.nacos.file.parse;

import java.io.IOException;
import java.io.StringReader;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author snailhd
 */
public class PropertiesFileParser extends AbstractFileParser {

    @Override
    public ConcurrentHashMap<String, String> parse(String text) throws IOException {
        Properties properties = new Properties();
        StringReader stringReader = new StringReader(text);
        properties.load(stringReader);
        Enumeration<?> enumeration = properties.propertyNames();
        ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>(properties.size());
        while (enumeration.hasMoreElements()){
            String key = (String)enumeration.nextElement();
            map.put(key,properties.getProperty(key));
        }
        return map;
    }
}
